﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.Entity;
using System.Text;
using System.Threading.Tasks;
using TGBTech.Core.Models.BaoCao.SoChiTietVLSPHHModel;
using TGBTech.Core.Models.ChungTu;
using TGBTech.Core.Models.BaoCao;

namespace TGBTech.Core.Models.Services
{
    public class SoChiTietSPVLHHServices
    {
        public SoChiTietVLSPHH So;
        public static String TAIKHOAN = "156";
        
        /// <summary>
        /// 
        /// </summary>
        public SoChiTietSPVLHHServices()
        {
            So = new SoChiTietVLSPHH();
        }

        public bool CreateSo(String MaHang, DateTime? TuNgay, DateTime? DenNgay)
        {
            // Validate data
            if(MaHang == null || MaHang == "" || TuNgay.HasValue == false || DenNgay.HasValue == false)
            {
                return false;
            }

            // Check MaHang is Exist?
            using (var db = new TGB.Core.Infrastructure.TGBTechDb())
            {
                // Select HangHoa by MaHang
                var HangHoaes = db.HangHoa.Where(p => p.MaHangHoa == MaHang).ToList();

                if(HangHoaes.Count == 0)
                {
                    return false;
                }

                // Set value for So
                var objHangHoa = HangHoaes.First();

                //So.HangHoaId = MaHang;
                //So.HangHoaTen = objHangHoa.Name;
                //So.HangHoaQuyCach = objHangHoa.QuyCach;
                //So.DonViTinh = objHangHoa.DVT;
                //So.TaiKhoanId = TAIKHOAN;

                // Caculate ChiTietSo
                So.ListModel = CreateChiTietSo(MaHang, TuNgay, DenNgay);

            }

            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="MaHang"></param>
        /// <param name="TuNgay"></param>
        /// <param name="DenNgay"></param>
        /// <returns></returns>
        private List<SoChiTietVLSPHHModel> CreateChiTietSo(String MaHang, DateTime? TuNgay, DateTime? DenNgay)
        {
            List<SoChiTietVLSPHHModel> List = new List<SoChiTietVLSPHHModel>();

            using (var db = new TGB.Core.Infrastructure.TGBTechDb())
            {
               
            }

            return List;
        }
    }
}
